package com.sunspring.zdcall.aop;

import com.sunspring.zdcall.common.constant.WebConstant;
import com.sunspring.zdcall.common.exception.AuthException;
import com.sunspring.zdcall.entity.ZdUserInfo;
import com.sunspring.zdcall.support.ContextHolder;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author wulei
 * @date 2018-12-29
 **/
@Component
public class LoginInterceptor implements HandlerInterceptor {


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        ZdUserInfo userInfo = (ZdUserInfo) request.getSession().getAttribute(WebConstant.SESSION_LOGIN_KEY);
//        if (userInfo == null) {
//            //跳转登录页
//            response.sendRedirect("/login");
//            return false;
//        }
//        else {
//            ContextHolder.add(userInfo);
//        }
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        ContextHolder.remove();
    }
}
